<template>
  <el-dialog title="新增菜单" :visible.sync="isshow.sta">
    <el-form :model="form">
      <el-form-item label="上级菜单">
        <el-select v-model="form.pid" placeholder="请选择活动区域">
          <el-option label="顶级菜单" :value="0"></el-option>
          <el-option
            :label="xin.title"
            :value="xin.id"
            v-for="xin in menuList"
            :key="xin.id"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="菜单类型">
        <el-radio-group v-model="form.type">
          <el-radio :label="2">目录</el-radio>
          <el-radio :label="1">菜单</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item label="菜单名称">
        <el-input v-model="form.title"></el-input>
      </el-form-item>
      <el-form-item label="菜单地址" v-if="form.type != 2 ? true : false">
        <el-input v-model="form.url"></el-input>
      </el-form-item>
      <el-form-item label="菜单图标" v-if="form.type != 1 ? true : false">
        <el-input v-model="form.icon"></el-input>
      </el-form-item>
      <el-form-item label="菜单状态">
        <el-radio-group v-model="form.status">
          <el-radio :label="1">正常</el-radio>
          <el-radio :label="0">禁用</el-radio>
        </el-radio-group>
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button>取 消</el-button>
      <el-button type="primary" @click="baocun">确 定</el-button>
    </div>
  </el-dialog>
</template>

<script>
export default {
  data() {
    return {
      form: {
        id: 0,
        icon: " ",
        pid: 0,
        status: 1,
        title: " ",
        url: " ",
        type: 1,
      },
    };
  },
  props: ["menuList", "isshow"],
  methods: {
    xiugaiM(obj) {
      this.form = { ...obj };
    },
    baocun() {
      let url = "";
      if (this.form.id == 0) {
        url = "/api/menuadd";
      } else {
        url = "/api/menuedit";
      }
      this.$http.post(url, this.form).then((res) => {
        console.log(res);
        this.isshow.sta = false;
      });
      this.form = {
        id: 0,
        icon: " ",
        pid: 0,
        status: 1,
        title: " ",
        url: " ",
        type: 1,
      };
      this.$emit("chongqi");
    },
  },
};
</script>

<style>
</style>